package rohyunji;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class MEMBERDAO extends _SubDAO{
	
	MemberVO mv=null;	
	public MEMBERDAO() {}
	
	String countlogin="select count(mb_no) from member where mb_id=? and mb_pw=?";
	String selectMb_type="select mb_type from member where mb_id=? ";
	String insertSQL = "insert into COMPANY values(exam.nextval,?,?,?,?,?,?,?,?,?,?)";
	String	selectMb_no="select mb_no from member where mb_id=?";
	@Override
	public int countMember(MemberVO mv) {
		// TODO Auto-generated method stub
		Connection c=null;  PreparedStatement p=null;
		ResultSet rs=null;int  cnt=0;
		try
		{

			c=openDataBase();
			p=c.prepareStatement(countlogin);
			p.setString(1, mv.getMb_id());
			p.setString(2, mv.getMb_pw());
			rs=p.executeQuery();
	
			if(rs.next())
			{

				cnt=rs.getInt(1);
			
			
			}
		}catch(Exception e){e.printStackTrace();}
		finally{super.closeDataBase(c, p, null);}
		return cnt;
		
	}
	  public List<MemberVO> SelectMember(MemberVO mv) 
      {
              Connection c=null;  PreparedStatement p=null;
              ResultSet rs=null;
              List<MemberVO> result = new ArrayList<>();
              try {
                      c = openDataBase();
                      p = c.prepareStatement(selectMb_type);
                      p.setString(1, mv.getMb_id());
                      rs = p.executeQuery();
                      while(rs.next())
                      {
                              MemberVO m = new MemberVO();
                              m.setMb_type(rs.getString("mb_type"));
                              result.add(m);
                      }
              } catch (Exception e) {e.printStackTrace();} 
              finally {super.closeDataBase(c, p, null);}

              return result;

      }
@Override
public boolean InsertMember(CompanyVO c) {
	// TODO Auto-generated method stub
	Connection conn = null;
	PreparedStatement pstmt = null;
	boolean result = false;
	
	try{
		conn = openDataBase();
		pstmt = conn.prepareStatement(insertSQL);
		
		
		pstmt.setString(1,c.getMb_no());
		pstmt.setString(2,c.getCp_reg_no());
		pstmt.setString(3,c.getCp_name());
		pstmt.setString(4,c.getCp_pre());
		pstmt.setString(5,c.getCp_addr());
		pstmt.setString(6,c.getCp_phone());
		pstmt.setString(7,c.getCp_job_type());
		pstmt.setString(8,c.getCp_scale());
		pstmt.setString(9,c.getCp_content());
		pstmt.setString(10,c.getCp_incor_day());
		
		pstmt.executeUpdate();
		result = true;
		
	}catch (Exception ex) {
		ex.printStackTrace();
	}finally {
		closeDataBase(conn, pstmt, null);}
	return result;
	
	
}

	public List<MemberVO> SelectMb_no(MemberVO mv)

	{
		Connection c = null;
		PreparedStatement p = null;
		ResultSet rs = null;
		List<MemberVO> result = new ArrayList<>();
		try {
				c = openDataBase();
				p = c.prepareStatement(selectMb_no);
				p.setString(1, mv.getMb_id());
				rs = p.executeQuery();
				while (rs.next()) {
				MemberVO m = new MemberVO();
				m.setMb_no(rs.getString("mb_no"));
				result.add(m);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			super.closeDataBase(c, p, null);
		}

		return result;
	}

}
